home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / corelib / ncbitime.c < prev    next >
Text File  |  1996-07-05  |  4KB  |  140 lines

  1. /*  ncbitime.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE                          
  5. *               National Center for Biotechnology Information
  6. *                                                                          
  7. *  This software/database is a "United States Government Work" under the   
  8. *  terms of the United States Copyright Act.  It was written as part of    
  9. *  the author's official duties as a United States Government employee and 
  10. *  thus cannot be copyrighted.  This software/database is freely available 
  11. *  to the public for use. The National Library of Medicine and the U.S.    
  12. *  Government have not placed any restriction on its use or reproduction.  
  13. *                                                                          
  14. *  Although all reasonable efforts have been taken to ensure the accuracy  
  15. *  and reliability of the software and data, the NLM and the U.S.          
  16. *  Government do not and cannot warrant the performance or results that    
  17. *  may be obtained by using this software or data. The NLM and the U.S.    
  18. *  Government disclaim all warranties, express or implied, including       
  19. *  warranties of performance, merchantability or fitness for any particular
  20. *  purpose.                                                                
  21. *                                                                          
  22. *  Please cite the author in any work or product based on this material.   
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  ncbitime.c
  27. *
  28. * Author:  Ostell, Kans
  29. *
  30. * Version Creation Date:  1/1/90
  31. *
  32. * $Revision: 2.1 $
  33. *
  34. * File Description:
  35. *   misc portable routines for
  36. *   dates, times, timers
  37. *
  38. * Modifications:  
  39. * --------------------------------------------------------------------------
  40. * Date     Name        Description of modification
  41. * -------  ----------  -----------------------------------------------------
  42. * 04-15-93 Schuler     Changed _cdecl to LIBCALL
  43. * ==========================================================================
  44. */
  45.  
  46. #include <ncbi.h>
  47. #include <ncbiwin.h>
  48.  
  49. char * NCBI_months[12] = {
  50.     "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
  51.     "Nov", "Dec"};
  52. static char * ampm[2] = {
  53.     "AM", "PM" };
  54.  
  55.  
  56. /*****************************************************************************
  57. *
  58. *   Nlm_GetSecs()
  59. *       returns computer time in seconds - for timing purposes only
  60. *
  61. *****************************************************************************/
  62. time_t LIBCALL  Nlm_GetSecs (void)
  63.  
  64. {
  65.     return  time(NULL);
  66. }
  67.  
  68. /*****************************************************************************
  69. *
  70. *   Nlm_GetDayTime(DayTimePtr)
  71. *
  72. *****************************************************************************/
  73. Nlm_Boolean LIBCALL  Nlm_GetDayTime (Nlm_DayTimePtr dtp)
  74.  
  75. {
  76.     time_t ltime;
  77.     struct tm *dt;
  78.  
  79.     Nlm_MemFill ((Nlm_VoidPtr) dtp, 0, sizeof(Nlm_DayTime));
  80.     time(<ime);
  81.     if ((dt = localtime (<ime)) != NULL)
  82.      {
  83.         Nlm_MemCopy ((Nlm_VoidPtr) dtp, (Nlm_VoidPtr) dt, sizeof (struct tm));
  84.         return TRUE;
  85.     }
  86.     return FALSE;
  87. }
  88.  
  89. /*****************************************************************************
  90. *
  91. *   Nlm_DayTimeStr(buf, date, time)
  92. *       fills buffer with formatted date and/or time
  93. *       date requires a 13 character buffer
  94. *       time requeres a 10 character buffer
  95. *       data and time takes 23
  96. *
  97. *       eg.   "Jan 28, 1988 12:59 PM"
  98. *
  99. *****************************************************************************/
  100. Nlm_Boolean LIBCALL  Nlm_DayTimeStr (Nlm_CharPtr buf, Nlm_Boolean nlm_date, Nlm_Boolean nlm_time)
  101.  
  102. {
  103.     Nlm_DayTime dt;
  104.     char localbuf[30];
  105.     int pm;
  106.     
  107.     buf[0] = '\0';
  108.  
  109.     if ( ! Nlm_GetDayTime(&dt))
  110.         return FALSE;
  111.  
  112.     if (nlm_date)
  113.     {
  114.         sprintf (localbuf, "%s %d, %d", NCBI_months [dt.tm_mon], 
  115.                     dt.tm_mday, dt.tm_year + 1900);
  116.         StringCpy (buf, localbuf);
  117.     }
  118.     if (nlm_time)
  119.     {
  120.         pm = 1;
  121.         if (dt.tm_hour == 0)
  122.         {
  123.             dt.tm_hour = 12;
  124.             pm = 0;
  125.         }
  126.         else if (dt.tm_hour < 12)
  127.             pm = 0;
  128.         else if (dt.tm_hour > 12)
  129.             dt.tm_hour -= 12;
  130.  
  131.         sprintf (localbuf, "%3d:%2d %s", dt.tm_hour, dt.tm_min, ampm[pm]);
  132.         if (dt.tm_min < 10)
  133.             localbuf[4] = '0';
  134.         StringCat (buf, localbuf);
  135.     }
  136.     return TRUE;
  137. }
  138.  
  139.